package edu.pku.sei.transformation.editor.views.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;

public class ExpressionFigure extends Label {
	private LineBorder border = new LineBorder() {
		public void paint(IFigure figure, Graphics graphics, Insets insets) {
			tempRect.setBounds(getPaintRectangle(figure, insets));
			if (getWidth() % 2 == 1) {
				tempRect.width--;
				tempRect.height--;
			}
			tempRect.shrink(getWidth() / 2, getWidth() / 2);
			graphics.setLineWidth(getWidth());
			graphics.setLineStyle(getStyle());
			if (getColor() != null)
				graphics.setForegroundColor(getColor());
			graphics.drawLine(new Point(tempRect.x, tempRect.y+tempRect.height), new Point(tempRect.x+tempRect.width, tempRect.y+tempRect.height));
		}
	};

	public ExpressionFigure() {
		// this.setIcon(IconsProvider.getImage(IconsProvider.EXPRESSION_ICO));
		this.setFont(FontConstant.BODY_FONT);
		this.setBorder(border);
		border.setColor(ColorConstants.white);
	}

	public void setHighLight(boolean isHighLight) {
		if (isHighLight) {
			border.setColor(ColorConstants.red);
		} else {
			border.setColor(ColorConstants.white);
		}
	}
	@Override
	public Dimension getPreferredSize(int wHint, int hHint) {
		System.out.println("size:"+wHint+"-"+hHint);
		Dimension d =  super.getPreferredSize(wHint, hHint);
		System.out.println("prefer:"+d.width+"-"+d.height);
		System.out.println(getParent().getSize().width);
		d.width = Math.max(getParent().getSize().width - 2, 10);
		return d;
	}
}
